package com.bawei.aspectj

import android.util.Log
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.RoutePath
import com.tencent.mmkv.MMKV
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Pointcut

/**
 * Author: Jason Zhang
 * Date: 2025/2/7
 * Desc: 自定义切面类
 */

@Aspect
class CheckLoginAspect {

    //定义切点, execution(@注解的全路径包名.注解名称 * *(..))
    @Pointcut("execution(@com.bawei.aspectj.CheckLoginState * *(..))")
    fun checkLogin(){}

    //自定义切点的处理逻辑
    @Around("checkLogin()")
    fun aroundCheckLogin(process: ProceedingJoinPoint){
        Log.i("================", "aroundCheckLogin: ============")
        var userToken = MMKV.defaultMMKV().decodeString("token", "")
        if (userToken.isNullOrEmpty()){
            ARouter.getInstance().build(RoutePath.PATH_LOGIN_PAGE).navigation()
        }else{
            //处理完了，让业务方继续执行其他逻辑
            process.proceed()
        }
    }



}